extends "../cTDW_2/cTDW_2.gd"
func _info():
	pass

func _connect():
	._connect()

func _extInit():
	._extInit()
	chaName = "骑士王"
	lv = 3
	attCoe.atkRan = 2
	attCoe.atk = 50 / 8.5 * 2 / 3
	attCoe.maxHp = 960 / 112.5 / 3
	attAdd.dod = 0.17
	addCdSkill("qsw1",5)
	addSkillTxt("极速支援：[主动]跳到我方生命比最低的单位，消耗自身3%血量，为自身和该单位附加消耗血量值的护盾并使所有对其仇恨转移到自身[cd:5秒][被动]闪避+17%")
	addSkillTxt("极速反击：成功闪避时，对攻击者造成150%魔法伤害[无cd]；护盾破裂时对周围九宫格敌人造成lv*90点真伤并附加1层<眩晕>[cd:2秒]")
	if !is_connected("afterhurtshield",self,"check"):
		connect("afterhurtshield",self,"check")
		
var cdflag = 0
var cnt = 0
func _onBattleStart():
	._onBattleStart()
	cnt = 0
	cdflag = 0

func _castCdSkill(id):
	._castCdSkill(id)
	if id == "qsw1":
		var chas = getAllChas(2)
		var chas2 = getAllChas(1)
		chas.sort_custom(self,"sort2")
		for i in chas:
			if i == self:continue
			self.plusHp(-att.hp*0.03)
			i.changeShield(att.hp * 0.03)
			changeShield(att.hp * 0.03)
			for j in chas2:
				if j.aiCha == i:
					j.aiCha = self
			break

func _onHurt(atkinfo):
	if atkinfo.isMiss:
		hurtChara(atkinfo.atkCha,att.atk*1.5,Chara.HurtType.MGI,Chara.AtkType.SKILL)

func check():
	if self.shield <= 0 && !cdflag:
		var dmg = lv * 90
		var vs = [Vector2(1,0),Vector2(-1,0),Vector2(0,1),Vector2(0,-1),Vector2(1,1),Vector2(-1,1),Vector2(-1,-1),Vector2(1,-1)]
		var c = cell
		for i in vs:
			if sys.main.isMatin(i + c):
				var cha = matCha(i + c)
				if !cha:continue
				if cha.get("team") != self.team:
					cha.addBuff(ctrl.b_xuanyun.new(1))
					hurtChara(cha,dmg,Chara.HurtType.REAL,Chara.AtkType.SKILL)
func _upS():
	._upS()
	if cdflag:
		cnt += 1
		if cnt == 2:
			cnt = 0
			cdflag = 0

func sort2(a,b):
	return (a.att.hp / a.att.maxHp) < (b.att.hp / b.att.maxHp) 